// 混入代码 resize-mixins.js
import { debounce } from '@/utils/index'
import { countries as COUNTRIES } from '@/config/countries'
const resizeChartMethod = '$__resizeChartMethod'

export default {
  data () {
    // 在组件内部将图表init的引用映射到chart属性上
    return {
      // chart: null
    }
  },
  created () {
    window.addEventListener('resize', this[resizeChartMethod], false)
  },
  beforeDestroy () {
    window.removeEventListener('reisze', this[resizeChartMethod])
  },
  methods: {
    getCountryByLang (country) {
      if (this.$store.state.locale === 'en-US') {
        const cont = COUNTRIES.find(c => c.label === country)
        return cont ? cont.ENLabel : ''
      }
      return country
    },
    // 通过lodash的防抖函数来控制resize的频率
    [resizeChartMethod]: debounce(function () {
      if (this._chart) {
        this._chart.resize()
      }
    }, 100)
  }
}
